package com.ssm.tool;

import org.slf4j.Logger;

import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;


public class CompletableFutureUtils {

    public static <T> T getResult(Future<T> future, //具体执行方法函数
                                  Long timeOut, //超时时间
                                  TimeUnit timeUnit,
                                  T defaultValue, //默认值
                                  Logger logger //日志对象
    ) {
        try {
            return future.get(timeOut, timeUnit);
        } catch (Exception e) {
            logger.error("CompletableFutureUtils.getResult.error:{}", e.getMessage(), e);
            return defaultValue;
        }
    }
}
